/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.customer.core.repository.entity.CustomerOperatorEntity;
import info.peigen.hotpot.business.customer.manage.convertor.CustomerOperatorManageConvertor;
import info.peigen.hotpot.business.customer.manage.form.CustomerOperatorManageCreateForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerOperatorManageEditForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerOperatorManageSearchForm;
import info.peigen.hotpot.business.customer.manage.info.CustomerOperatorManageInfo;
import info.peigen.hotpot.business.customer.manage.repository.service.CustomerOperatorManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(CustomerOperatorManageService)</b>
 * 管理后台 "客户操作员" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-09-08
 */
@SuppressWarnings("unused")
@Component
public class CustomerOperatorManageService {
    @Inject
    CustomerOperatorManageRepository customerOperatorManageRepository;

    public PageResult<CustomerOperatorManageInfo> page(CustomerOperatorManageSearchForm form) {
        LambdaQuery<CustomerOperatorEntity> lambdaQuery = customerOperatorManageRepository.getMapper().createLambdaQuery()
                .andLike(CustomerOperatorEntity::getOperatorId, Query.filterLikeEmpty(form.getOperatorId(), false, true))
                .andLike(CustomerOperatorEntity::getCustomerId, Query.filterLikeEmpty(form.getCustomerId(), false, true))
                .andLike(CustomerOperatorEntity::getLoginName, Query.filterLikeEmpty(form.getLoginName(), false, true))
                .andLike(CustomerOperatorEntity::getStatus, Query.filterLikeEmpty(form.getStatus(), false, true))
                .andLike(CustomerOperatorEntity::getDeleteFlag, Query.filterLikeEmpty(form.getDeleteFlag(), false, true))
                .andLike(CustomerOperatorEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return customerOperatorManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, CustomerOperatorManageConvertor::convertToInfo);
    }

    public void create(CustomerOperatorManageCreateForm form) {
        CustomerOperatorEntity entity = BeanUtil.copyProperties(form, CustomerOperatorEntity.class);
        customerOperatorManageRepository.save(entity);
    }

    public void edit(CustomerOperatorManageEditForm form) {
        CustomerOperatorEntity entity = BeanUtil.copyProperties(form, CustomerOperatorEntity.class);
        customerOperatorManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        customerOperatorManageRepository.delete(id);
    }
}